<?php
namespace Admin\Model;
use \Think\Model;

class CatsModel extends Model {
		protected $cats = array();

	public function __construct() {
	    parent::__construct();
        $this->cats = $this->select();
	}
	public function getTree($p_id=0 , $lev=0) {
		$tree = array();
		foreach($this->cats as $v) {
			if( $v['pid'] == $p_id ) {
				$v['lev'] = $lev;
				$tree[] = $v;
                 //把$V的cat_id拿出来 再传递给getTree方法
				//然后把foreach打印出来的$tree数组 用array_marge合并起来 赋给$tree变量
			   	$tree = array_merge( $tree , $this->getTree($v['cat_id'] , $lev+1) );
			}           
		  }
		  return $tree;	
	}
}





?>